package com.gitee.feizns.web.utils;

import java.util.Iterator;
import java.util.function.Predicate;

/**
 * @author feizns
 * @since 2019/10/18
 */
public abstract class IteratorUtils {

    /**
     * 迭代器查询
     * @param it
     * @param test
     * @param <T>
     * @return
     */
    public static <T> int indexOf(Iterator<T> it, Predicate<T> test) {
        int index = 0;
        while( it.hasNext() ) {
            if ( test.test(it.next()) )
                return index;
            index++;
        }
        return -1;
    }

}
